package org.example.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Size;
import java.util.Date;

@Data
@TableName("user")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User {
    public interface Register{ }
    public interface Login{ }
    public interface LoginByMail{ }
    public interface Update{ }
    public interface save{ }

    //分组校验，在修改和登录对参数的校验方式不同
    @NotNull(message = "用户id不能为空",groups = Update.class)
    @Null(message = "用户id必须为空",groups = {Register.class, Login.class, LoginByMail.class, save.class})
    @TableId(value = "id", type = IdType.AUTO)
    private Integer userId;

    @NotNull(message = "用户账号不能为空",groups = {Login.class, Register.class, save.class})
    @Null(message = "用户账号必须为空",groups = {LoginByMail.class})
    @Size(min = 4, max = 11, message = "账号长度必须是4-11个字符")
    private String username;

    @NotNull(message = "用户密码不能为空",groups = {Login.class, Register.class})
    @Null(message = "用户密码必须为空",groups = {LoginByMail.class})
    @Size(min = 4, max = 16, message = "密码长度必须是4-16个字符")
    @TableField(select = false)
    private String password;

    @NotNull(message = "邮箱不能为空",groups = {LoginByMail.class, Register.class, save.class})
    @Null(message = "邮箱必须为空",groups = {Login.class})
    private String mail;

    @TableField(value = "icon", fill = FieldFill.INSERT)
    private String icon;

    @TableField(value = "plus", fill = FieldFill.INSERT)
    private Integer plus;

    @TableField(exist = false)
    private String role;

    @TableField(exist = false)
    private String token;

    @NotNull(message = "验证码不能为空",groups = {LoginByMail.class, Register.class, Login.class})
    @TableField(exist = false)
    private String checkCode;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time",fill = FieldFill.UPDATE)
    private Date updateTime;

}
